package com.glut.gultguy.mq;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.glut.gultguy.entity.Goods;
import com.glut.gultguy.entity.GoodsAuctionRecord;
import com.glut.gultguy.mapper.GoodsAuctionRecordMapper;
import com.glut.gultguy.mapper.GoodsMapper;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@RocketMQMessageListener(topic = "java1234-rocketmq",consumerGroup
        ="${rocketmq.consumer.group}" )
@Component
public class Consumer implements RocketMQListener<String> {

    @Autowired(required = false)
    private GoodsMapper goodsMapper;

    @Autowired(required = false)
    private GoodsAuctionRecordMapper goodsAuctionRecordMapper;
    @Override
    public void onMessage(String s) {

      try {
          System.out.println("收到消息内容："+s);
          Goods goods = goodsMapper.selectOne(new QueryWrapper<Goods>().eq("id",s));
          goods.setGoodsState(3);
          goods.setAuctioning(false);
          GoodsAuctionRecord record = goodsAuctionRecordMapper.selectOne(new QueryWrapper<GoodsAuctionRecord>().eq("goodsId",goods.getId()).orderByDesc("putPrice").last("limit 1"));
          goodsAuctionRecordMapper.deleteRecode(goods.getId());
          goods.setBuyer_openid(record.get_openid());
          goodsMapper.updateById(goods);
          goodsAuctionRecordMapper.insert(record);
      }catch (Exception e){

      }




    }

}
